<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <%@ include file="top_new.jsp"%> 
    <link rel="stylesheet" href="/css/pintuer.css">
</head>
<body>
<div style="bottom: 0;border: solid 1px #1AA094;width: 190px;VERFLOW: auto;" >
	<ul class="layui-tree">
  
    <li><a  href="javascript:void(0)"  onclick="refresh('')"><h2>文章类别</h2><a></a></li>
    <c:forEach items="${tdic}" var="s">
	    <li class="site-tree-noicon ">
	      <a  href="javascript:void(0)"  onclick='refresh(${s.fode})'>
	        <cite>【${s.fode}】${s.fvalue}</cite>
	      </a>
	    </li>
	</c:forEach>
  </ul>
</div>
<div class="layui-body"  >
  <div class="padding border-bottom layui-form-item">
    <div class="layui-input-inline">
      <input type="text" name="fvalue" id = "fvalue" placeholder="文章名称" autocomplete="off" class="layui-input">
    </div>
    <button class="layui-btn" id ="query">查询</button>
    <button class="layui-btn layui-btn-primary" style="float: right;">
    	<a href="javascript:" id="batch" title="批量对话框">
	    	<i class="layui-icon">&#xe634;</i> 
	    	批量发布
	    	<span class="badge" id="batch_num" style="background-color: red">0</span>
    	</a>
    </button>
  </div>
<div class="layui-tab-item layui-show">
    	<table class="layui-table" id="no_list">
		  <colgroup>
		    <col width="50%">
		    <col width="10%">
		    <col width="20%">
		    <col width="20%">
		  </colgroup>
		  <thead>
		    <tr>
		      <input type="hidden" name="fid" id="fid" >	
		      <input type="hidden" name="fcounts" id="fcounts" >	
		      <th name ="ftitle" id="ftitle">标题	</th>
		      <th name ="fdescribe" id="fdescribe">来源</th>
		      <th name ="fctime" id="fdate">抓取时间</th>
		      <th >操作</th>
		    </tr> 
		  </thead>
		  <tbody id = "t_tbody">
		  </tbody>
		    <tr>
		       <td colspan="10"><div id="div_page" style="float: right;"></div></td>
		    </tr>
		</table>	
</div>
</div>

<script type="text/javascript"> 
window.onload=function() {
	var index = layer.load(2, {time: 10000}); //又换了种风格，并且设定最长等待10秒 
	$.post("<%=basePath%>grid/toResutList",
		    {
				page:1,
				pagesize:10,
				fstatus:0
		    },
		    function(res){
		    	if (res.errorCode == 0) {
		    		var data=res.data;
		    		laypage({
		    		      cont: 'div_page', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
		    		      pages: data.totalPage, //通过后台拿到的总页数
		    		      curr: data.pageNumber, //当前页
		    		      jump: function(obj, first){ //触发分页后的回调
		    		    	  $("#t_tbody").empty();
		    		    	  if(!first){
			    		    	  $.post("<%=basePath%>grid/toResutList", 
			    		    			    {
			    		    					page:obj.curr,
			    		    					pagesize:10,
			    		    					fstatus:0
			    		    			    },
			    		    			    function(res){
			    		    			    	var tbody ="";
		    		    			    		if (res.errorCode == 0) {
			    		    			    		 tbody = pageGirdUp(res.data.list,2);  
		    		    			    		}
		    		    			    		$("#counts").html("总行数:"+res.data.totalRow);
		    		    			    		$("#t_tbody").append(tbody);
		    		    			    		layer.close(index); 
			    		    			    });
		    		    	  }else{
		    		    		   var tbody ="";
		    		    		   tbody = pageGirdUp(data.list,2);  
		    		    		   $("#counts").html("总行数:"+res.data.totalRow);
		    			    	   $("#t_tbody").append(tbody);  
		    			    	   layer.close(index); 
		    		    	  }
		    		    	 
		    		      }
		    		});
		    	}else{
		    		if (res.errorCode == 2) {
		    			layer.alert(res.message) ;
		    		}else{
		    			layer.msg("参数错误："+res.message, {shift: 6});
		    		}
		    	}
		    }); 
};
$("#bt_add").click(function(){
	var diag = new top.Dialog();
    diag.Drag=true;
    diag.Title ="用户编辑";
    diag.URL = 'http://www.baidu.com';
    diag.Width = 400;
    diag.Height = 400;
    diag.CancelEvent = function(){ //关闭事件
        diag.close();
    };
    diag.show();
});



function refresh(ftype){
	var index = layer.load(2, {time: 10000}); //又换了种风格，并且设定最长等待10秒 
	 $.post("<%=basePath%>grid/toResutList",
			    {
					page:1,
					pagesize:10,
					fvalue: $("#fvalue").val(),
					ftype:ftype
			    },
			    function(res){
			    	if (res.errorCode == 0) {
			    		var data=res.data;
			    		laypage({
			    		      cont: 'div_page', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
			    		      pages: data.totalPage, //通过后台拿到的总页数
			    		      curr: data.pageNumber, //当前页
			    		      jump: function(obj, first){ //触发分页后的回调
			    		    	  $("#t_tbody").empty();
			    		    	  if(!first){
				    		    	  $.post("<%=basePath%>grid/toResutList",
				    		    			    {
				    		    					page:obj.curr,
				    		    					pagesize:10,
				    		    					fvalue: $("#fvalue").val(),
				    		    					ftype:ftype
				    		    			    },
				    		    			    function(res){
				    		    			    	var tbody ="";
			    		    			    		if (res.errorCode == 0) {
				    		    			    		 tbody = pageGirdUp(res.data.list,2);  
			    		    			    		}
			    		    			    		$("#counts").html("总行数:"+res.data.totalRow);
			    		    			    		$("#t_tbody").append(tbody);  
			    		    			    		layer.close(index); 
				    		    			    });
			    		    	  }else{
			    		    		   var tbody ="";
			    		    		   tbody = pageGirdUp(data.list,2);  
			    		    		   $("#counts").html("总行数:"+res.data.totalRow);
			    			    	   $("#t_tbody").append(tbody);  
			    			    	   layer.close(index); 
			    		    	  }
			    		    	 
			    		      }
			    		});
			    	}else{
			    		if (res.errorCode == 2) {
			    			layer.alert(res.message) ;
			    		}else{
			    			layer.msg("参数错误："+res.message, {shift: 6});
			    		}
			    	}
			    }); 
}
$("#query").click(function(){ 
	refresh("");
})
function del(id){
	if(confirm("您确定要删除吗?")){
		$.post("<%=basePath%>grid/grid_del",
		    {
				fid:id
		    },
		    function(res){
		    	if (res.errorCode == 0) {
		    		window.location.reload();
		    	}else{
		    		if (res.errorCode == 2) {
		    			layer.alert(res.message) ;
		    		}else{
		    			layer.msg("参数错误："+res.message, {shift: 6});
		    		}
		    	}
		    }); 
	}
}

function cancle(id){
	if(confirm("确定需要取消文章审核?")){
		var index = layer.load(2, {time: 10000}); //又换了种风格，并且设定最长等待10秒 
		$.post("<%=basePath%>grid/gridCancle",
			    {
					fid:id
			    },
			    function(ret){
			    	if (ret.isOk) {
			    		layer.msg('文章已审核,查看请到审核列表', {icon: 1});
			    		window.location.reload();
			    	}else{
			    		layer.msg(ret.msg, {shift: 6});
			    	}
			    	//关闭
					layer.close(index); 
			    }); 
	}
}
function send(id){
	//先弹出去向选择 dialog
	easyDialog.open({
		container : 'dialogSingle',
		overlay : false,
		yesText : 'yesBtn',
		noText : 'noBtn',
	});
	$("#sendidval").attr("value",id);
}

function noFunc(){
	$("#sendidval").attr("value","");
	easyDialog.close();
}

function yesFunc(){
	var id = $("#sendidval").val();
	if(id != "" && id != null){
		//获取复选框的内容
		var arr = document.getElementsByName("toSingle");
		var strs = new Array();
		for(i = 0;i<arr.length;i++){
			if(arr[i].checked){
				strs.push(arr[i].value);
			}
		}
		if(strs[0] != null && strs[0] != ""){
			//提交数据到后台
			$.ajax({  
	            type:'post',  
	            traditional :true,  
	            url:'<%=basePath%>grid/grid_send',  
	            data:{
		            	fid:id,
						tos:strs
	            	},  
	            success:function(res){  
	            	if (res.errorCode == 0) {
	            		if(res.toWhere != "" && res.toWhere != null){
	            			var direction = res.toWhere;
	            			$("#td"+id).append("<div class='divtip'>"+direction+"</div>");
	            		}
	            		easyDialog.close();
	            		layer.msg("发布成功!", {shift: 1});
					   	//window.location.reload();
					}else{
					    if (res.errorCode == 2) {
					    	layer.msg(res.message, {shift: 6});
					    }
					}
	            }  
	        }); 
		}else{
			layer.msg("你没有选择发布去向!", {shift: 6});
		}
	}else{
		layer.msg("参数错误!发布的内容不能为空!", {shift: 6});
	}
}

function prew(id){
	window.open('<%=basePath%>grid/grid_view?fid='+id); 
}
function eidt(id){
	window.open('<%=basePath%>grid/toNewGrid?fid='+id); 
}
$("#checkall").click(function(){ 
  $("input[name='id']").each(function(){
	  if (this.checked) {
		  this.checked = false;
	  }
	  else {
		  this.checked = true;
	  }
  });
})

function DelSelect(){
	var Checkbox=false;
	 $("input[name='id']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){
		var t=confirm("您确认要删除选中的内容吗？");
		if (t==false) return false; 		
	}
	else{
		alert("请选择您要删除的内容!");
		return false;
	}
}

//添加到批量操作列表
function add(id){
	var id = id;
	$.post("<%=basePath%>grid/batch_add",
		    {
				fid:id
		    },
		    function(ret){
		    	if (ret.isOk) {
		    		var direct = "";
		    		var direaction = ret.t.fareadySend;
		    		if(direaction != "" && direaction != null){
		    			direct = "<div class='divtip'>"+direaction+"</div>";
		    		}
		    		$("#batch_tbody").append(
		    			"<tr id='tr"+ret.t.fid+"'>"+
		    				"<td style='font-size: 10px;'>"+ret.t.ffrom+"</td>"+
		    				"<td style='font-size: 10px;'>"+ret.t.ftitle+" "+direct+"</td>"+
		    				"<td style='font-size: 10px;'>"+ret.t.fdescribe+"</td>"+
		    				"<td>"+
		    					"<a class='button-group' href='javascript:' id='"+ret.t.fid+"' onclick='removeTr(this.id)'>"+
		    						"<i class='layui-icon' style='font-size: 25px; color: #e33;'>&#xe640;</i>"+
		    					"</a>"+
		    				"</td>"+
		    			"</tr>"
		    		);
		    		//变换数量
		    		var num = $("#batch_num").text();
		    		$("#batch_num").text(parseInt(num)+1);
		    		//设置不能再点击
		    		$("#"+id).attr("disabled","true");
		    		$("#"+id).css("background-color","gray");
		    	}else{
		    		layer.msg("参数错误："+ret.msg, {shift: 6});
		    	}
		    }); 
}

//从批量列表中删除该元素
function removeTr(id){
	var fu = "#tr"+id;;
	$(fu).remove();
	var num = $("#batch_num").text();
	if(num <= 0){
		
	}else{
		$("#batch_num").text(parseInt(num)-1);
		$("#"+id).removeAttr("disabled");
		$("#"+id).css("background-color","white");
	}
}

//弹出批量操作dialog
$("#batch").click(function (){
	easyDialog.open({
		container : 'dialogBatch',
		overlay : false
	});
});

//点击批量发布
function sendbatch(){
	//获取所有的选出的id-tr
	var index = layer.load(2, {time: 10000});
	var arr = new Array();
	$("#batch_tbody").find("tr").each(function (){
		arr.push(this.id);
	});
	//如果数组不为空 ，则将数据传入后台
	if(arr.length > 0){
		$.ajax({  
            type:'post',  
            traditional :true,  
            url:'<%=basePath%>grid/batch_sendBatch',  
            data:{
            		ids:arr
            	},  
            success:function(ret){  
                 if(ret.errorCode == 0){
                	 setTimeout(function () {
                		 layer.close(index);
 		    	  	 }, 500);
                	 setTimeout(function () {
                		 layer.msg("全部上传成功!", {shift: 1});
 		    	  	 }, 500);
                	 setTimeout(function () {
                    	 window.location.reload();
 		    	  	 }, 1500);
                 }else{
                	 setTimeout(function () {
                		 layer.close(index);
 		    	  	 }, 500);
                	 setTimeout(function () {
                		 layer.msg(ret.num+"条数据上传成功!", {shift: 1});
 		    	  	 }, 500);
                	 setTimeout(function () {
                    	 window.location.reload();
 		    	  	 }, 1500);
                 } 
            }  
        });  
	}else{
		layer.close(index);
		layer.msg("没有选择要发布的内容!", {shift: 6});
	}
}

function closeThis(){
	easyDialog.close();
}

</script>
<style type="text/css">
		.divtip{float:right;margin-right: 30px;background: red;color: black;height: 15px;width: 50px;line-height: 15px;font-size: 8px;border-radius: 5px;text-align: center;}
		h3{color:#333;font-size:14px;width:250px;margin:30px auto 0;}
		.hide_box{width:300px;color:#fff;color:#444;background:#fff;box-shadow:1px 2px 2px #555;display:none;}
		.hide_box h4{height:26px;line-height:26px;overflow:hidden;background:#f7b64b;color:#fff;padding:0 10px;border:1px solid #e78f08;font-size:14px;border-bottom:1px solid #eaa12a;}
		.hide_box h4 a{width:14px;line-height:13px;_line-height:15px;height:13px;font-family:arial;overflow:hidden;display:block;background:#fff;color:#c77405;float:right;text-align:center;text-decoration:none;margin-top:7px;font-size:14px;font-weight:normal;border-radius:2px;_font-size:12px;}
		.hide_box p{padding:30px 10px;font-size:13px;border:1px solid #ccc;}
		
		.send_btn{position:absolute;bottom:0;}
</style>
	<div class="hide_box" id="dialogSingle" style="display: none; margin: 0px;height: 150px;width: 500px;border:1px solid #009688;border-radius:5px; " >
		<h4><a href="javascript:void(0)" onclick="closeThis()" title="关闭窗口">×</a>发布</h4>
		<form class="layui-form" action="">
			<div class="layui-form-item">
				<div class="layui-input-block" style="margin-top:15px;" id="singleBox">
					<input type="checkbox"  value="WX" name="toSingle" title="微信端">
				    <input type="checkbox"  value="942游戏" name="toSingle" title="942游戏">
				</div>
			</div>
		</form>
		
		<div style="height: 65px;width: 100%" class="send_btn">
			<div align="center" style="margin-top: 10px;">
				<input type="hidden" value="" id="sendidval">
				<button class="layui-btn layui-btn-radius" id="yesBtn" onclick="yesFunc()">确定</button>
				<button class="layui-btn layui-btn-radius" id="noBtn" onclick="noFunc()">取消</button>
			</div>
		</div>
	</div>

	<div class="hide_box" id="dialogBatch" style="display: none; margin: 0px;height: 600px;width: 700px;border:1px solid #009688;border-radius:5px;" > 
		<h4><a href="javascript:void(0)" id="closeBtn" title="关闭窗口">×</a>批量发布</h4> 
		<div style="overflow-y:auto; overflow-x:hidden; width:100%;height: 400px;" class="layui-tab layui-tab-brief">
		  <div class="layui-tab-content" style="height: 100%;">
		    <div class="layui-tab-item layui-show">
		    	<table class="layui-table">
			    	<colgroup>
			    		<col width="20%">
					    <col width="50%">
					    <col width="20%">
					    <col width="10%">
					</colgroup>
					<thead>
					    <tr>
					      <th id="fffrom">作者</th>
					      <th id="fftitle">标题</th>
					      <th id="fftitle">来源</th>
					      <th >操作</th>
					    </tr> 
					</thead>
					<tbody id = "batch_tbody">
				  	 	
				  	</tbody> 
				</table> 
		    </div>
  		   </div>
		</div>
		
		<blockquote class="layui-elem-quote layui-quote-nm">
			<form class="layui-form" action="">
				<div class="layui-form-item">
				    <label class="layui-form-label">去向</label>
				    <div class="layui-input-block" id="batchBox">
				      <input type="checkbox"  value="WX" name="toBatch"  title="微信端">
				      <input type="checkbox"  value="942" name="toBatch"  title="942游戏">
				    </div>
				</div>
			</form>
			
			<div style="height: 65px;width: 100%" class="send_btn">
				<div align="center" style="margin-top: 10px;">
					<button class="layui-btn" id="sendBatch" onclick="sendbatch()" style="width: 100px;">发布</button>
				</div>
			</div>
		</blockquote>
	</div>
</div>
</body>
</html>